﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewTools
{
    internal class ControlUtil
    {
        private MainWindow mMainWindow;

        private static ControlUtil controlUtil = null;

        public ControlUtil(MainWindow mainWindow)
        {

            this.mMainWindow = mainWindow;
        }

        public static ControlUtil GetInstance(MainWindow mainWindow)
        {
            if(controlUtil == null)
                controlUtil = new ControlUtil(mainWindow);
            return controlUtil;
        }

        public void TvSerialControlEnable_Set(bool enable)
        {
            mMainWindow.comboBox_serial_port.Enabled = enable;
            mMainWindow.Manual_Send_Button.Enabled = !enable;
            mMainWindow.Button_Auto_Start.Enabled = !enable;
            mMainWindow.ButtonTvRefresh.Enabled = enable;
        }

        public void SignalControlEnable_Set(bool enable)
        {
            mMainWindow.NumericUpDownTimming.Enabled = enable;
            mMainWindow.NumericUpDownPattern.Enabled = enable;
            mMainWindow.ButtonTimming.Enabled = enable;
            mMainWindow.ButtonPattern.Enabled = enable;
            mMainWindow.ButtonSignalRefresh.Enabled = !enable;
            mMainWindow.TextBoxSignalReceive.Enabled = enable;
        }

        public  void StatusBarTvSerialPortLabel_Set(string info)
        {
            mMainWindow.TvSTatusLabel.Text = info;
        }

        public void SignalBoxNumber_Set()
        {
            string timmingNum = ParseIni.GetInstance().TimmingNumber_Read();
            string patternNum = ParseIni.GetInstance().PatternNumber_Read();
            mMainWindow.NumericUpDownTimming.Value = Convert.ToDecimal(timmingNum);
            mMainWindow.NumericUpDownPattern.Value = Convert.ToDecimal(patternNum);
        }

        public  void CurrentTime_Get()
        {
            DateTime dateTime = DateTime.Now;
            mMainWindow.TimeStatusLabel.Text = dateTime.ToString();
        }

        public void ModelComboBox_Set()
        {
            mMainWindow.ComboBoxModel.Items.AddRange(FileOperation.GetInstance().GetModelItemsByFolder());
            string name = ParseIni.GetInstance().ModelName_Read();
            Console.WriteLine(name);
            mMainWindow.ComboBoxModel.Text = name;
        }
    }
}
